#ifndef UPGRADETOOL_H
#define UPGRADETOOL_H

#include <QMainWindow>
#include "ui_upgradetool.h"

#include <QMessageBox>
#include <QtSerialPort>
#include <QSerialPortInfo>
#include <QMessageBox>
#include <QAbstractItemView>
#include <QFileDialog>
#include <QDebug>

#include "Ymodem/YmodemFileTransmit.h"
#include "Ymodem/YmodemFileReceive.h"

class UpgradeTool : public QMainWindow
{
    Q_OBJECT

public:
    explicit UpgradeTool(QWidget *parent = nullptr);
    ~UpgradeTool();

signals:
    void setstatemsg(QString color,QString str);

private slots:
    void led_timer_irq();
    void ss_timer_irq();
    void on_btn_find_seriaport_clicked();   // 搜索串口按键
    void on_btn_open_port_clicked();        // 打开串口按键 
    void on_transmitBrowse_clicked();       // 浏览按键
    void on_btn_start_update_clicked();     // 启动升级 按键
    void on_btn_stop_update_clicked();      // 取消升级 按键
    void ReadData(); // 接收数据
    void transmitProgress(int progress);
    void transmitStatus(YmodemFileTransmit::Status status);
private:
    QTimer *led_timer;
    QTimer *serial_timer;
    QSerialPort *serialPort;
    YmodemFileTransmit *ymodemFileTransmit;
    YmodemFileReceive *ymodemFileReceive;

    bool transmitButtonStatus;
    bool receiveButtonStatus;

    int find_led_timer = 0;
private:
    Ui::UpgradeTool *ui;
    void Find_SerialPort();
    void on_transmitButton_clicked();
    QSerialPort::StopBits to_convert_stopbit(QString bit);
    QSerialPort::DataBits to_convert_databit(QString  bit);
    QSerialPort::Parity to_convert_paritybit(QString  bit);
};




#endif // UPGRADETOOL_H


